package com.itobase.statusDetect.Controller;

import com.itobase.statusDetect.Model.Teaching;
import com.itobase.statusDetect.Repository.TeachingRepository;
import com.itobase.statusDetect.Service.TeachingService;
import com.itobase.statusDetect.Util.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.InvalidParameterException;

/**
 * @author htyu
 * @date 2019/2/24
 */

@RestController
@RequestMapping("teaching")
public class TeachingController {

    @Autowired
    TeachingRepository teachingRepository;

    @Autowired
    TeachingService teachingService;


    @PostMapping("/create")
    public Message create(@RequestBody Teaching teaching){
        try {
            return Message.success(teachingService.create(teaching));
        }catch (InvalidParameterException e){
            return Message.error("教学班已存在，请勿重复添加");
        }
    }

    @GetMapping("list")
    public Message getList(@RequestParam(required = false) String keyword){
        return Message.success(teachingService.getList(keyword));
    }
}
